package com.example.javamaday.leetcode;

public class LeetCodeTest0048 {

    public static void main(String[] args) {

        int[][] matrix = new int[][]{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};

        System.out.println(matrix[2][0]);
    }


    public void rotate(int[][] matrix) {
        int tRow = 0;
        int tCol = 0;
        int dRow = matrix.length - 1;
        int dCol = matrix[0].length - 1;
        while (tRow < dRow) {
            rotateMatrix(matrix, tRow++, tCol++, dRow--, dCol--);
        }
    }

    private void rotateMatrix(int[][] m, int tRow, int tCol, int dRow, int dCol) {
        int times = dRow - tRow;
        for (int i = 0; i < times; i++) {
            // 0 0
            int tmp = m[tRow][tCol + i];
            // 0 0 <--- 2 0
            m[tRow][tCol + i] = m[dRow - i][tCol];
            // 2 0 <--- 2 2
            m[dRow - i][tCol] = m[dRow][dCol - i];
            // 2 2 <--- 0 2
            m[dRow][dCol - i] = m[tRow + i][dCol];
            // 0 2 <--- 0 0
            m[tRow + i][dCol] = tmp;
        }
    }


}
